package com.lpz.dao;

import com.lpz.domain.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

/**
 * 手动编写实现类
 */
public class UserDaoimpl  implements IUserDao{
    private SqlSessionFactory factory;
    public UserDaoimpl(SqlSessionFactory factory){
        this.factory=factory;
    }
    public List<User> findAll() {
        //1使用工厂创建sqlsession对象
        SqlSession session=factory.openSession();
        //2使用session执行查询所有方法,参数是映射配置文件中的namespace和对应的sqlid
        List<User> users=session.selectList("com.lpz.dao.IUserDao.findAll");
        session.close();
        //3返回查询结果
        return users;
    }
}
